package cocoaas3.Titanium.UI{
	import jp.progression.casts.*;import jp.progression.commands.display.*;import jp.progression.commands.lists.*;import jp.progression.commands.managers.*;import jp.progression.commands.media.*;import jp.progression.commands.net.*;import jp.progression.commands.tweens.*;import jp.progression.commands.*;import jp.progression.data.*;import jp.progression.events.*;import jp.progression.loader.*;import jp.progression.*;import jp.nium.core.debug.Logger;import jp.nium.utils.*;import caurina.transitions.Tweener;import caurina.transitions.properties.*;
	import flash.events.*;import flash.display.*;import flash.system.*;import flash.utils.*;import flash.net.*;import flash.media.*;import flash.geom.*;import flash.text.*;import flash.media.*;import flash.system.*;import flash.ui.*;import flash.external.ExternalInterface;import flash.filters.*;

	import org.osflash.signals.*;


	public class Window extends Sprite{

		public var openComplete_sig:Signal = new Signal()



		// -----------------------------------
		// オリジナル
		// -----------------------------------

		// For modal windows, hide the nav bar (true) or show the nav bar (false).
		private var _navBarHidden:Boolean = false;
		public function set navBarHidden( val:Boolean ):void{
			_navBarHidden = val;
			if( navBarHidden ){
				view.y = 0;
				removeChild( _navigationBar );
			} else {
				view.y = 88;
				addChild( _navigationBar );
			}
		}
		public function get navBarHidden():Boolean{
			return _navBarHidden;
		}

		public function set rightNavButton( val:DisplayObject ):void{
			_navigationBar.rightNavButton = val;
		}




		// -----------------------------------
		// カスタム
		// -----------------------------------
		private var self:Window;
		private var _navigationBar:NavigationBar = new NavigationBar();
		private var bg_mc:Sprite = new Sprite();
		private var view:Sprite = new Sprite();
		private var _modalMode:Boolean = false;

		public function Window(){
			view.y = 88;
		}


		public function add( mc:DisplayObject ):void{
			view.addChild( mc );
		}

		public function open( modal:Boolean=false ):void{
			_modalMode = modal;

			
			CastDocument.stage.addChild( this );
			CastDocument.stage.mouseChildren = false;
			var slist = new SerialList();

			if( _modalMode ){
				this.addChild( view );
				this.addChild( _navigationBar );
				this.y = CastDocument.bottom;		
				slist.addCommand(
					new DoTweener( this, {y:0, time:0.33, transition:"easeOutSine"} ),
				null);
			} else {
				var g:Graphics = bg_mc.graphics;
				g.beginFill( 0x000000, 0.33 );
				g.drawRect( 0, 0, CastDocument.right, CastDocument.bottom );
				this.addChild( bg_mc );
				this.addChild( view );

				view.x = CastDocument.right/2;
				view.y = CastDocument.bottom/2
				this.alpha = 0;
				slist.addCommand(
					new DoTweener( this, {alpha:1, time:0.33} ),
				null);
			}
			slist.addCommand(
				function(){
					CastDocument.stage.mouseChildren = true;
					openComplete_sig.dispatch()
				},
			null);
			slist.execute();

		}

		public function close():void{
			CastDocument.stage.mouseChildren = false;
			var slist = new SerialList();
			if( _modalMode ){
				slist.addCommand(
					new DoTweener( this, {y:CastDocument.bottom, time:0.33, transition:"easeInSine"} ),
				null);
			} else {
				slist.addCommand(
					new DoTweener( this, {alpha:0, time:0.33} ),
				null);
			}
			slist.addCommand(
				new RemoveChild( CastDocument.stage, this ),
				function(){
					CastDocument.stage.mouseChildren = true;
				},
			null);
			slist.execute();			
		}

	}
}






import flash.display.*

class NavigationBar extends Sprite{

	[Embed(source="../../assets.swf", symbol='NavigationBar_design')]
	private var NavigationBar_design:Class;

	private var design = new NavigationBar_design();




	private var _rightNavButton:DisplayObject;
	public function set rightNavButton( val:DisplayObject ):void{
		if( _rightNavButton ){
			removeChild( _rightNavButton );
		}
		addChild( val );
	}


	public function NavigationBar(){
		addChild( design );
	}

}











